<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/view/common/taglibs.jsp" %>
<script type="text/javascript">
function selectObject(){
	var shopType = <s:property value="@com.jysz.certificate.persistence.enums.OrganizationEnum@SHOP.index"/>;
	var staffType = <s:property value="@com.jysz.certificate.persistence.enums.OrganizationEnum@STAFF.index"/>;
	var tp = document.getElementById("tp").value;
	if(type == shopType){
		window.open("${contextPath}/system/treaty/selectCheckShop.do?allIds="+$('#shops_id').val(), "newwindow", "height=900, width=1024, toolbar =no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
	}else if(type == staffType){
// 		var isShop = <s:if test="entity.parent != null && @com.jysz.certificate.persistence.enums.OrganizationEnum@SHOP.equals(entity.parent.type)">1</s:if><s:else>0</s:else>;
// 		var url= "<s:property value='contextPath'/>/system/user/choose.do?currentPage=${currentPage}&us.isShop=" + isShop;
// 		window.open(url,'选择用户','height=900,width=1024,top=0,left=200,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no');
		var url= "${contextPath}/system/user/chooseUser.do?post="+tp+"&allIds="+$("#users_id").val();
		window.open(url,'选择用户','height=900,width=1024,top=0,left=200,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no');
	}
	
}
function choose_user(ids,names){
	$("#users_id").val(ids);
	$("#nameField").val(names);
}
function choose_shop(ids,names){
	$("#shops_id").val(ids);
	$("#nameField").val(names);
}
function changeType(value){

	type = value;
	var orgType = <s:property value="@com.jysz.certificate.persistence.enums.OrganizationEnum@ORG.index"/>;
	if(orgType == value){
		//TODO:名称可以编辑，选择框消失
		$("#nameField").attr({"readonly":false});
		$("#nameField").removeClass("input_readOnly_80").addClass("input_90");
	//	$('#selectObjectField').toggle();
		$('#selectObjectField').css('display','none');
	}else{
		//TODO:名称不可编辑，出现选择框	
		$("#nameField").attr({"readonly":"readonly"});
		$("#nameField").removeClass("input_90").addClass("input_readOnly_80");
		$('#selectObjectField').css('display','inline-block');
		//$('#selectObjectField').toggle();
	}
	
	$("#nameField").attr({"value":""});
	$("#objectIdField").attr({"value":""});
}
var type = <s:property value="entity.type != null ? entity.type.index : entity.parent != null && @com.jysz.certificate.persistence.enums.OrganizationEnum@SHOP.equals(entity.parent.type) ? @com.jysz.certificate.persistence.enums.OrganizationEnum@STAFF.index : 0"/>;
$(document).ready(function(){readyChangeType(type)});

function readyChangeType(value){

	type = value;
	var orgType = <s:property value="@com.jysz.certificate.persistence.enums.OrganizationEnum@ORG.index"/>;
	if(orgType == value){
		//TODO:名称可以编辑，选择框消失
		$("#nameField").attr({"readonly":false});
		$("#nameField").removeClass("input_readOnly_80").addClass("input_90");
	//	$('#selectObjectField').toggle();
		$('#selectObjectField').css('display','none');
	}else{
		//TODO:名称不可编辑，出现选择框	
		$("#nameField").attr({"readonly":"readonly"});
		$("#nameField").removeClass("input_90").addClass("input_readOnly_80");
		$('#selectObjectField').css('display','inline-block');
		//$('#selectObjectField').toggle();
	}
	
}

function selectShopCallBack(hao, ming, id){
	$("#nameField").attr({"value":ming});
	$("#objectIdField").attr({"value":id});
}

// function choose_user(id_,name_){
// 	$("#nameField").attr({"value":name_});
// 	$("#objectIdField").attr({"value":id_});
// }
//-->
</script>
	<input type='hidden' name='search.name' value='${search.name}'/>
	<input type='hidden' name='parentId' value='${parentId}'/>
	<input type='hidden' name='redirectUrl' value='<s:property value='redirectUrl'/>'/>
	<input type='hidden' id="objectIdField" name='entity.objectId' value='${entity.objectId}'/>
	<input type="hidden" id="users_id" name="userIds" value="">
	<input type="hidden" id="shops_id" name="shopIds" value="">
	<input type="hidden" id="tp" value="<s:property value='entity.parent.type.index'/>"/>
	
	<table width="100%" border="0" cellpadding="1" cellspacing="1">
		<tr>
			<td class="left-td-width-bg">
				<font color="red">*</font>编码：
			</td>
			<td>
				<input name="entity.code" class="input_readOnly_99" type="text" id="code" size="16" readonly="readonly"
					value="<s:property value='entity.code'/>" dataType="Require|Unique"  msg="必填项|编码必须是唯一" classType="com.jysz.certificate.persistence.model.system.Organization" valProperty="code" entityId="${entity.id}" contextPath="${contextPath}"/>
			</td>
	
			<td class="left-td-width-bg">
					<font color="red">*</font>类型：
				</td>
				<td width="15%">
				
				<s:if test="entity.childs != null && entity.childs.size() > 0">
					<input type="hidden" name="entity.type" value="${entity.type.index}"/>
					<s:property value="entity.type"/>
				</s:if>
				<s:else>
					<s:iterator value="@com.jysz.certificate.persistence.enums.OrganizationEnum@values()">
						<s:if test="entity.parent==null">
							<label><input type="radio" <s:if test="index==0">checked</s:if> <s:else>disabled</s:else> onchange="javascript:changeType(this.value);" name="entity.type" value="<s:property value="index"/>"/><s:property value="name"/></label>
						</s:if>
						<s:else>
							<s:if test="entity.parent.type.index==1">
								<s:if test="index==2">
									<label><input type="radio" checked name="entity.type" value="<s:property value="index"/>"/><s:property value="name"/></label>
								</s:if>
								<s:else>
									<label><input type="radio" disabled name="entity.type" value="<s:property value="index"/>"/><s:property value="name"/></label>
								</s:else>
							</s:if>
							<s:else>
								<label><input type="radio" <s:if test="index==0">checked</s:if> onchange="javascript:changeType(this.value);" name="entity.type" value="<s:property value="index"/>"/><s:property value="name"/></label>
							</s:else>
						</s:else>
					</s:iterator>
				</s:else>
				
				</td>
			<td class="left-td-width-bg">
				<font color="red">*</font>名称：
			</td>
			<td>
				<input name="entity.name" id="nameField" class="input_90"  type="text" id="name" size="16"
					 value="<s:property value='entity.name'/>" dataType="Require"  msg="名称不能为空" />&nbsp;
				<span id="selectObjectField" style="display: none;">
					<a href="javascript:selectObject();"><img src="${contextPath}/images/chakan.gif"/></a>
				</span>
			</td>	

		</tr>
			<tr>
				<td class="left-td-width-bg">
					<font color="red">*</font>排序：
				</td>
				<td>
					<input name="entity.order" class="input" type="text" id="order" size="16" readonly="readonly"
						value="<s:property value='entity.order'/>" onchange="javascript:changeCode(this.value);" />
				</td>	
				<td colspan="4"></td>			
			</tr>

	</table>
	 <table width="100%">
            	<tr>
                	<td><div align="center">
                	  <input type="submit" name="submit" value="" class="btn_save" />
                	&nbsp;&nbsp;
                      <input type="reset" name="reset" value="" class="btn_rest" onclick="clearForm(this.form);return false;"/>
                    </div>
                    </td>
                </tr>
     </table>        